package com.government.web.controller.company;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.government.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.government.common.annotation.Log;
import com.government.common.core.controller.BaseController;
import com.government.common.core.domain.AjaxResult;
import com.government.common.enums.BusinessType;
import com.government.company.domain.Industry;
import com.government.company.service.IIndustryService;
import com.government.common.utils.poi.ExcelUtil;

/**
 * 行业信息Controller
 * 
 * @author system
 * @date 2023-10-31
 */
@RestController
@RequestMapping("/company/industry")
public class IndustryController extends BaseController
{
    @Autowired
    private IIndustryService industryService;

    /**
     * 查询行业信息列表
     */
    @PreAuthorize("@ss.hasPermi('company:industry:list')")
    @GetMapping("/list")
    public AjaxResult list(Industry industry)
    {
        List<Industry> list = industryService.selectIndustryList(industry);
        return success(list);
    }

    /**
     * 导出行业信息列表
     */
    @PreAuthorize("@ss.hasPermi('company:industry:export')")
    @Log(title = "行业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Industry industry)
    {
        List<Industry> list = industryService.selectIndustryList(industry);
        ExcelUtil<Industry> util = new ExcelUtil<Industry>(Industry.class);
        util.exportExcel(response, list, "行业信息数据");
    }

    /**
     * 获取行业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('company:industry:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(industryService.selectIndustryById(id));
    }

    /**
     * 新增行业信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('company:industry:add')")
    @Log(title = "行业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Industry industry)
    {
        return toAjax(industryService.insertIndustry(industry));
    }

    /**
     * 修改行业信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('company:industry:edit')")
    @Log(title = "行业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Industry industry)
    {
        return toAjax(industryService.updateIndustry(industry));
    }

    /**
     * 删除行业信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('company:industry:remove')")
    @Log(title = "行业信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(industryService.deleteIndustryById(id));
    }

    /**
     * 行业树
     */
    @GetMapping("/industryTree")
    public AjaxResult industryTree()
    {
        return success(industryService.industryTree());
    }
}
